package univer.oko.queryAnalizer.sqlEditor;

import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultStyledDocument;

/**
 * Created by Sergey Kharlamov.
 * Date: 23.07.2006
 * Time: 12:02:58
 */
public class CDDocument extends DefaultStyledDocument {
    /**
     * Osnovnoj komponent Zebry
     */
    CDEditorPane cdSourceWindow = null;

    /**
     * Initsializirujuschij konstruktor
     */
    public CDDocument(CDEditorPane window) {
        super();
        cdSourceWindow = window;
    }

    /**
     * Obrabotchik sobytija dobavlenija teksta.
     */
    public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
        super.insertString(offs, str, a);
        //JOptionPane.showMessageDialog(null,"insertString "+str);
//        try {
//            int caretPos = cdSourceWindow.getEditorPane().getCaretPosition();
//
//            super.insertString(offs, str, a);
//
//            if (cdSourceWindow != null) {
//                if (!cdSourceWindow.isUndoBlocked())
//                    cdSourceWindow.addEditEvent(offs, str.length(), str, caretPos, true);
//
//                cdSourceWindow.updateLineNumbersAreaWidth(false);
//
        cdSourceWindow.parseText();
        cdSourceWindow.formatText();

//            }
//        } catch (Throwable e) {
//        }
    }

    /**
     * Obrabotchik sobytija udalenija teksta.
     */
    public void remove(int offs, int len) throws BadLocationException {
        super.remove(offs, len);
        //  JOptionPane.showMessageDialog(null,"removestring  "+len);

//        try {
//            int carretPos = cdSourceWindow.getEditorPane().getCaretPosition();
//            String text = getText(offs, len);
//
//            super.remove(offs, len);
//
//            if (cdSourceWindow != null) {
//                if (!cdSourceWindow.isUndoBlocked())
//                    cdSourceWindow.addEditEvent(offs, len, text, carretPos, false);
//
//                cdSourceWindow.updateLineNumbersAreaWidth(false);
//
        cdSourceWindow.parseText();
        cdSourceWindow.formatText();
//            }
//        } catch (Throwable e) {
//        }
    }
}
